import React from "react";
import { Link, Route, Switch, Redirect } from "react-router-dom";

class Home extends React.Component {
  render() {
    return (
      <>
        <div>home页面</div>
      </>
    );
  }
}

const About = () => {
  return <div>about页面</div>;
};

const NotFound = () => {
  return <div>404 not found ...</div>;
};

const App = () => {
  return (
    <>
      <h2>react-router-v5-404页面</h2>
      <ul>
        <li>
          <Link to="/home">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
      </ul>

      <hr />

      <Switch>
        {/* path="*" */}
        {/* 要写在所有Route的最下面 */}
        {/* 必须要加Switch */}
        <Redirect from="/" to="/home" exact></Redirect>
        <Route path="/home" component={Home}></Route>
        <Route path="/about" component={About}></Route>
        <Route path="*" component={NotFound}></Route>
      </Switch>
    </>
  );
};

export default App;
